﻿using Abp.TestBase;
using AVIS.OutBound.EntityFramework;
using EntityFramework.DynamicFilters;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AVIS.OutBound.Tests
{
    public class AvisTestBase : AbpIntegratedTestBase<AvisOutBoundTestModule>
    {
        protected AvisTestBase()
        {
            //Seed initial data
            //UsingDbContext(context =>
            //{
            //    new InitialDbBuilder(context).Create();
            //    new TestDataBuilder(context).Create();
            //});

            //LoginAsDefaultTenantAdmin();
        }

        protected override void PreInitialize()
        {
            base.PreInitialize();

            //Fake DbConnection using Effort!
            //LocalIocManager.IocContainer.Register(
            //    Component.For<DbConnection>()
            //        .UsingFactoryMethod(DbConnectionFactory.CreateTransient)
            //        .LifestyleSingleton()
            //    );
        }

        protected void UsingDbContext(Action<OutBoundDbContext> action)
        {
            using (var context = LocalIocManager.Resolve<OutBoundDbContext>())
            {
                context.DisableAllFilters();
                action(context);
                context.SaveChanges();
            }
        }
    }
}
